<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI对话平台 - 多页面对话</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --accent: #4895ef;
            --light: #f8f9fa;
            --dark: #212529;
            --success: #4cc9f0;
            --warning: #f72585;
            --gray: #6c757d;
            --light-gray: #e9ecef;
            --border-radius: 12px;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            color: var(--dark);
        }

        .container {
            width: 100%;
            max-width: 1200px;
            background: white;
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            overflow: hidden;
            display: flex;
            flex-direction: column;
            height: 90vh;
        }

        header {
            background: var(--primary);
            color: white;
            padding: 20px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            font-size: 1.5rem;
            font-weight: 700;
        }

        .logo i {
            color: var(--success);
        }

        .tabs-container {
            background: var(--light);
            border-bottom: 1px solid var(--light-gray);
            padding: 0 20px;
            display: flex;
            overflow-x: auto;
        }

        .tabs {
            display: flex;
            gap: 8px;
            padding: 15px 0;
        }

        .tab {
            background: white;
            padding: 10px 24px;
            border-radius: var(--border-radius) var(--border-radius) 0 0;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 8px;
            font-weight: 500;
            box-shadow: var(--shadow);
            transition: var(--transition);
            border: 1px solid var(--light-gray);
            border-bottom: none;
            position: relative;
        }

        .tab.active {
            background: white;
            color: var(--primary);
            font-weight: 600;
            border-bottom: 3px solid var(--primary);
        }

        .tab:hover {
            background: #f0f4ff;
        }

        .tab .close {
            color: var(--gray);
            font-size: 0.8rem;
            transition: var(--transition);
        }

        .tab .close:hover {
            color: var(--warning);
            transform: scale(1.1);
        }

        .add-tab {
            background: var(--primary);
            color: white;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            margin-left: 8px;
            transition: var(--transition);
        }

        .add-tab:hover {
            background: var(--secondary);
            transform: scale(1.05);
        }

        .main-content {
            display: flex;
            flex: 1;
            overflow: hidden;
        }

        .chat-container {
            flex: 1;
            display: flex;
            flex-direction: column;
            padding: 20px;
            background: #fafbff;
        }

        .chat-history {
            flex: 1;
            overflow-y: auto;
            padding: 20px;
            display: flex;
            flex-direction: column;
            gap: 20px;
            background: white;
            border-radius: var(--border-radius);
            margin-bottom: 20px;
            box-shadow: var(--shadow);
        }

        .message {
            max-width: 80%;
            padding: 16px 20px;
            border-radius: 20px;
            position: relative;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .user-message {
            align-self: flex-end;
            background: var(--primary);
            color: white;
            border-bottom-right-radius: 4px;
        }

        .ai-message {
            align-self: flex-start;
            background: var(--light-gray);
            color: var(--dark);
            border-bottom-left-radius: 4px;
        }

        .message-header {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 8px;
            font-weight: 600;
            font-size: 0.9rem;
        }

        .user-message .message-header {
            color: rgba(255, 255, 255, 0.9);
        }

        .ai-message .message-header {
            color: var(--primary);
        }

        .message-content {
            line-height: 1.5;
        }

        .typing-indicator {
            display: flex;
            align-items: center;
            gap: 4px;
            background: var(--light-gray);
            color: var(--gray);
            padding: 10px 16px;
            border-radius: 20px;
            align-self: flex-start;
            margin-top: 10px;
        }

        .typing-dot {
            width: 8px;
            height: 8px;
            background: var(--gray);
            border-radius: 50%;
            animation: typing 1.4s infinite;
        }

        .typing-dot:nth-child(2) {
            animation-delay: 0.2s;
        }

        .typing-dot:nth-child(3) {
            animation-delay: 0.4s;
        }

        @keyframes typing {
            0%, 60%, 100% { transform: translateY(0); }
            30% { transform: translateY(-5px); }
        }

        .input-container {
            display: flex;
            gap: 12px;
            background: white;
            border-radius: var(--border-radius);
            padding: 16px;
            box-shadow: var(--shadow);
        }

        .message-input {
            flex: 1;
            padding: 14px 20px;
            border: 2px solid var(--light-gray);
            border-radius: 30px;
            font-size: 1rem;
            outline: none;
            transition: var(--transition);
        }

        .message-input:focus {
            border-color: var(--accent);
        }

        .send-button {
            background: var(--primary);
            color: white;
            border: none;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            transition: var(--transition);
        }

        .send-button:hover {
            background: var(--secondary);
            transform: scale(1.05);
        }

        .send-button:disabled {
            background: var(--light-gray);
            cursor: not-allowed;
            transform: none;
        }

        .sidebar {
            width: 300px;
            background: white;
            padding: 20px;
            border-left: 1px solid var(--light-gray);
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .info-card {
            background: #f0f4ff;
            border-radius: var(--border-radius);
            padding: 20px;
            box-shadow: var(--shadow);
        }

        .info-card h3 {
            margin-bottom: 15px;
            color: var(--primary);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .model-info {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .model-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 12px;
            border-radius: 8px;
            transition: var(--transition);
            cursor: pointer;
        }

        .model-item:hover {
            background: #e6ebff;
        }

        .model-item.active {
            background: var(--primary);
            color: white;
        }

        .model-item.active .model-badge {
            background: white;
            color: var(--primary);
        }

        .model-badge {
            background: var(--accent);
            color: white;
            width: 28px;
            height: 28px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 0.8rem;
            font-weight: 600;
        }

        .stats {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
            margin-top: 20px;
        }

        .stat-card {
            background: white;
            border-radius: 10px;
            padding: 15px;
            text-align: center;
            box-shadow: var(--shadow);
        }

        .stat-value {
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--primary);
            margin: 8px 0;
        }

        .stat-label {
            font-size: 0.85rem;
            color: var(--gray);
        }

        @media (max-width: 900px) {
            .sidebar {
                display: none;
            }
        }

        @media (max-width: 600px) {
            body {
                padding: 10px;
            }
            
            .container {
                height: 95vh;
            }
            
            header {
                padding: 15px;
            }
            
            .logo {
                font-size: 1.2rem;
            }
            
            .tab {
                padding: 8px 16px;
                font-size: 0.9rem;
            }
            
            .chat-history {
                padding: 15px;
            }
            
            .message {
                max-width: 90%;
                padding: 12px 16px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <div class="logo">
                <i class="fas fa-robot"></i>
                <span>AI对话平台</span>
            </div>
            <div class="header-info">
                <span>多页面智能对话系统</span>
            </div>
        </header>
        
        <div class="tabs-container">
            <div class="tabs">
                <div class="tab active" data-tab="1">
                    <i class="fas fa-comments"></i>
                    <span>通用助手</span>
                    <i class="fas fa-times close"></i>
                </div>
                <div class="tab" data-tab="2">
                    <i class="fas fa-code"></i>
                    <span>编程助手</span>
                    <i class="fas fa-times close"></i>
                </div>
                <div class="tab" data-tab="3">
                    <i class="fas fa-language"></i>
                    <span>翻译助手</span>
                    <i class="fas fa-times close"></i>
                </div>
            </div>
            <div class="add-tab" id="add-tab">
                <i class="fas fa-plus"></i>
            </div>
        </div>
        
        <div class="main-content">
            <div class="chat-container">
                <div class="chat-history" id="chat-history-1">
                    <div class="message ai-message">
                        <div class="message-header">
                            <i class="fas fa-robot"></i>
                            <span>AI助手</span>
                        </div>
                        <div class="message-content">
                            您好！我是您的AI助手。请问有什么可以帮您的吗？我可以回答各种问题、提供建议或进行有趣的对话。
                        </div>
                    </div>
                </div>
                
                <div class="chat-history" id="chat-history-2" style="display:none">
                    <div class="message ai-message">
                        <div class="message-header">
                            <i class="fas fa-robot"></i>
                            <span>编程助手</span>
                        </div>
                        <div class="message-content">
                            您好！我是您的编程助手。我可以帮助您解决编程问题、解释代码概念、调试错误或提供代码示例。请告诉我您需要哪方面的帮助？
                        </div>
                    </div>
                </div>
                
                <div class="chat-history" id="chat-history-3" style="display:none">
                    <div class="message ai-message">
                        <div class="message-header">
                            <i class="fas fa-robot"></i>
                            <span>翻译助手</span>
                        </div>
                        <div class="message-content">
                            您好！我是您的翻译助手。我可以帮助您翻译多种语言之间的文本。请告诉我您需要翻译的内容和目标语言。
                        </div>
                    </div>
                </div>
                
                <div class="input-container">
                    <input type="text" class="message-input" id="message-input" placeholder="输入您的问题...">
                    <button class="send-button" id="send-button">
                        <i class="fas fa-paper-plane"></i>
                    </button>
                </div>
            </div>
            
            <div class="sidebar">
                <div class="info-card">
                    <h3><i class="fas fa-info-circle"></i> 当前对话信息</h3>
                    <p>页面: <span id="current-page">通用助手</span></p>
                    <p>消息数: <span id="message-count">1</span></p>
                    <p>状态: <span id="connection-status">已连接</span></p>
                </div>
                
                <div class="info-card">
                    <h3><i class="fas fa-brain"></i> AI模型选择</h3>
                    <div class="model-info">
                        <div class="model-item active">
                            <div class="model-badge">G4</div>
                            <div class="model-name">GPT-4 Turbo</div>
                        </div>
                        <div class="model-item">
                            <div class="model-badge">C3</div>
                            <div class="model-name">Claude 3</div>
                        </div>
                        <div class="model-item">
                            <div class="model-badge">G3</div>
                            <div class="model-name">Gemini Pro</div>
                        </div>
                        <div class="model-item">
                            <div class="model-badge">L3</div>
                            <div class="model-name">Llama 3</div>
                        </div>
                    </div>
                </div>
                
                <div class="stats">
                    <div class="stat-card">
                        <div class="stat-value">12</div>
                        <div class="stat-label">对话页面</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-value">347</div>
                        <div class="stat-label">今日消息</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-value">99.7%</div>
                        <div class="stat-label">可用性</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-value">0.8s</div>
                        <div class="stat-label">平均响应</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 当前活动标签页
            let activeTab = '1';
            
            // 获取DOM元素
            const tabs = document.querySelectorAll('.tab');
            const addTabBtn = document.getElementById('add-tab');
            const messageInput = document.getElementById('message-input');
            const sendButton = document.getElementById('send-button');
            const chatHistories = {
                '1': document.getElementById('chat-history-1'),
                '2': document.getElementById('chat-history-2'),
                '3': document.getElementById('chat-history-3')
            };
            
            // 标签切换功能
            tabs.forEach(tab => {
                tab.addEventListener('click', function(e) {
                    const tabId = this.getAttribute('data-tab');
                    
                    // 如果点击的是关闭按钮，则关闭标签页
                    if (e.target.classList.contains('close')) {
                        e.stopPropagation();
                        if (tabs.length > 1 && this.classList.contains('active')) {
                            // 切换到下一个标签页
                            const nextTab = this.nextElementSibling || this.previousElementSibling;
                            switchTab(nextTab.getAttribute('data-tab'));
                        }
                        this.remove();
                        return;
                    }
                    
                    // 切换标签页
                    switchTab(tabId);
                });
            });
            
            // 添加新标签页
            addTabBtn.addEventListener('click', function() {
                const tabCount = document.querySelectorAll('.tab').length;
                const newTabId = tabCount + 1;
                
                const newTab = document.createElement('div');
                newTab.className = 'tab';
                newTab.setAttribute('data-tab', newTabId);
                newTab.innerHTML = `
                    <i class="fas fa-comment-dots"></i>
                    <span>新对话 ${newTabId}</span>
                    <i class="fas fa-times close"></i>
                `;
                
                // 添加到标签列表
                document.querySelector('.tabs').appendChild(newTab);
                
                // 切换到新标签页
                switchTab(newTabId);
                
                // 添加点击事件
                newTab.addEventListener('click', function(e) {
                    const tabId = this.getAttribute('data-tab');
                    
                    if (e.target.classList.contains('close')) {
                        e.stopPropagation();
                        if (tabs.length > 1 && this.classList.contains('active')) {
                            const nextTab = this.nextElementSibling || this.previousElementSibling;
                            switchTab(nextTab.getAttribute('data-tab'));
                        }
                        this.remove();
                        return;
                    }
                    
                    switchTab(tabId);
                });
            });
            
            // 发送消息功能
            sendButton.addEventListener('click', sendMessage);
            messageInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter' && messageInput.value.trim() !== '') {
                    sendMessage();
                }
            });
            
            // 切换标签页函数
            function switchTab(tabId) {
                // 更新活动标签状态
                document.querySelectorAll('.tab').forEach(tab => {
                    if (tab.getAttribute('data-tab') === tabId) {
                        tab.classList.add('active');
                    } else {
                        tab.classList.remove('active');
                    }
                });
                
                // 更新聊天历史显示
                Object.keys(chatHistories).forEach(id => {
                    if (id === tabId) {
                        chatHistories[id].style.display = 'flex';
                    } else {
                        chatHistories[id].style.display = 'none';
                    }
                });
                
                // 更新当前标签页信息
                activeTab = tabId;
                const activeTabName = document.querySelector(`.tab[data-tab="${tabId}"] span`).textContent;
                document.getElementById('current-page').textContent = activeTabName;
                
                // 更新消息计数
                const messageCount = chatHistories[tabId].querySelectorAll('.message').length;
                document.getElementById('message-count').textContent = messageCount;
            }
            
            // 发送消息函数
            function sendMessage() {
                const message = messageInput.value.trim();
                if (message === '') return;
                
                // 添加用户消息
                addMessage('user', message, activeTab);
                
                // 清空输入框
                messageInput.value = '';
                
                // 禁用发送按钮
                sendButton.disabled = true;
                
                // 显示"正在输入"指示器
                showTypingIndicator(activeTab);
                
                // 模拟AI回复（实际应用中会调用后端API）
                setTimeout(() => {
                    // 移除"正在输入"指示器
                    removeTypingIndicator(activeTab);
                    
                    // 生成AI回复
                    let aiResponse;
                    switch(activeTab) {
                        case '1': // 通用助手
                            aiResponse = "感谢您的提问！我已经理解您的问题。根据我的知识库，这是一个非常有趣的话题。在实际应用中，这里会是AI模型生成的针对您问题的详细回答。";
                            break;
                        case '2': // 编程助手
                            aiResponse = "这是一个编程相关的问题。让我为您解释一下：在编程中，这个问题通常涉及核心概念。这里我会提供一个代码示例：\n\n```javascript\nfunction solveProblem(input) {\n  // 这里是解决方案\n  return input.map(item => item * 2);\n}\n```\n\n这个函数可以解决类似问题。";
                            break;
                        case '3': // 翻译助手
                            aiResponse = "您提供的文本翻译如下：\n\n中文：这是一个多页面对话应用示例\n英语：This is a multi-page conversation app example\n西班牙语：Este es un ejemplo de aplicación de conversación de varias páginas";
                            break;
                        default:
                            aiResponse = "我已经收到您的消息。在实际应用中，这里会是AI模型根据当前页面上下文生成的回复。";
                    }
                    
                    // 添加AI回复
                    addMessage('ai', aiResponse, activeTab);
                    
                    // 启用发送按钮
                    sendButton.disabled = false;
                    
                    // 更新消息计数
                    const messageCount = chatHistories[activeTab].querySelectorAll('.message').length;
                    document.getElementById('message-count').textContent = messageCount;
                }, 2000);
            }
            
            // 添加消息到聊天历史
            function addMessage(sender, content, tabId) {
                const chatHistory = chatHistories[tabId];
                const messageDiv = document.createElement('div');
                
                if (sender === 'user') {
                    messageDiv.className = 'message user-message';
                    messageDiv.innerHTML = `
                        <div class="message-header">
                            <i class="fas fa-user"></i>
                            <span>您</span>
                        </div>
                        <div class="message-content">${content}</div>
                    `;
                } else {
                    messageDiv.className = 'message ai-message';
                    messageDiv.innerHTML = `
                        <div class="message-header">
                            <i class="fas fa-robot"></i>
                            <span>AI助手</span>
                        </div>
                        <div class="message-content">${content}</div>
                    `;
                }
                
                chatHistory.appendChild(messageDiv);
                
                // 滚动到底部
                chatHistory.scrollTop = chatHistory.scrollHeight;
            }
            
            // 显示"正在输入"指示器
            function showTypingIndicator(tabId) {
                const chatHistory = chatHistories[tabId];
                const typingDiv = document.createElement('div');
                typingDiv.className = 'typing-indicator';
                typingDiv.id = `typing-${tabId}`;
                typingDiv.innerHTML = `
                    <span>AI助手正在输入</span>
                    <div class="typing-dot"></div>
                    <div class="typing-dot"></div>
                    <div class="typing-dot"></div>
                `;
                chatHistory.appendChild(typingDiv);
                
                // 滚动到底部
                chatHistory.scrollTop = chatHistory.scrollHeight;
            }
            
            // 移除"正在输入"指示器
            function removeTypingIndicator(tabId) {
                const typingIndicator = document.getElementById(`typing-${tabId}`);
                if (typingIndicator) {
                    typingIndicator.remove();
                }
            }
            
            // 初始化：显示第一条消息计数
            document.getElementById('message-count').textContent = 
                chatHistories[activeTab].querySelectorAll('.message').length;
        });
    </script>
</body>
</html>